<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>人员管理</title>
    <?php include(APPLICATION_BASE_TPL_PATH . "/inc/include.phtml"); ?>
</head>
<body>
<div id="wrapper">
    <?php echo $menuview; ?>
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<button type="button" class="btn btn-primary btn-lg right add-bottom" onclick="javascript:openDialog('Modal', url('/user/usermgrpop'));">&nbsp;&nbsp;&nbsp;新建&nbsp;&nbsp;&nbsp;</button>
				<h1 class="page-header">人员管理</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<!-- /.panel-heading -->
					<div class="panel-body">
						<div class="table-responsive">
							<table class="table" id="dataTables-admin">
								<thead>
								<tr>
									<th>用户名</th>
									<th>姓名</th>
									<th>手机</th>
                                    <th>描述</th>
									<th>角色</th>
									<th>操作</th>
								</tr>
								</thead>
								<tbody>
								<?php
								foreach ($users as $i=>$row) {
									?>
									<tr>
										<td><?php echo $row['uname'] ?></td>
										<td><?php echo $row['nick'] ?></td>
										<td><?php echo $row['phone'] ?></td>
                                        <td><?php echo $row['description'] ?></td>
										<td>
											<?php
											echo $row['isadmin'] ? '管理员' : '普通用户';
											echo $row['status'] ? '（已禁用）' : '';
											?></td>
										<td>
											<button onclick="javascript:openDialog('Modal', url('/user/usermgrpop/?uid=<?=$row['uid']?>'));" class="btn btn-primary btn-sm">
												&nbsp;&nbsp;编辑&nbsp;&nbsp;</button>
											<img src="<?=APP_STATIC_PATH?>/admin/img/line.png" alt="" name="eline" height="30px" width="1px">
											<a class="btn btn-primary btn-sm" href="<?=APP_ADMIN_PATH?>/group/usergroup?uid=<?=$row['uid']?>">用户组</a>
											<img src="<?=APP_STATIC_PATH?>/admin/img/line.png" alt="" name="eline" height="30px" width="1px">
											<a class="btn btn-primary btn-sm" onclick="javascript:acl(<?=$row['isadmin']?>,<?=$row['status']?>,<?=$row['uid']?>);">权限</a>
											<img src="<?=APP_STATIC_PATH?>/admin/img/line.png" alt="" name="eline" height="30px" width="1px">
											<button isban="<?php echo $row['status']; ?>" onclick="javascript:setBan(this, <?php echo $row['uid']; ?>);" type="button" name="bbutton" class="btn <?php echo $row['status']?'btn-danger':'btn-primary'; ?> btn-sm"><?=$row['status']?'解禁':'禁止'?></button>
										</td>
									</tr>
								<?php
								}
								?>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script>
// 设置启用、禁用
function setBan(obj, uid) {
    var self = $(obj), isban=self.attr('isban'), change={1:0,0:1};
    $.post(url('/user/setban'), {isban:change[isban], uid:uid}, function(json) {
        if(json.retcode == 2000000) {
            refresh();
        } else {
            alert(json.msg);
        }
    });
}

function acl(isadmin, isban, uid){
	if(isadmin || isban){
		alert('该用户为管理员或被冻结，不能修改访问控制！');
	}else{
		url = '<?=APP_ADMIN_PATH?>/acl/index/?uid='+uid
		location.href = url;
	}
}

</script>
</html>
